Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ConstantBackoff: always return the same duration #12

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

rohits1101
Copy link

@rohits1101 rohits1101 commented Apr 4, 2023

Write ConstantBackoff which always returns the same duration, except for the first attempt which is always a zero


This change is Reviewable

This does not do exponential backoff, but rather retries
with a constant time
@rohits1101 rohits1101 requested review from a team as code owners April 4, 2023 08:29
import "time"

func GetConstantPolicy(duration time.Duration, max int) Policy {
return GetExponentialPolicy(1, duration, max)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's really a constant, what would the max do? why not just write the constant policy?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's just write the constant policy that backs off by duration time.

Copy link

@cyberhck cyberhck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to request changes, sorry.

@rohits1101 rohits1101 changed the title feat: Add ConstantBackoff: a wrapper around ExponentialPolicy with multiplier set to 1 feat: Add ConstantBackoff: always return the same duration Apr 4, 2023
cyberhck
cyberhck previously approved these changes Apr 4, 2023
@github-advanced-security
Copy link

You have successfully added a new SonarCloud configuration ``. As part of the setup process, we have scanned this repository and found no existing alerts. In the future, you will see all code scanning alerts on the repository Security tab.

@rohits1101 rohits1101 requested a review from maetolay April 4, 2023 08:55
maetolay
maetolay previously approved these changes Apr 4, 2023
@rohits1101 rohits1101 force-pushed the feat/rohit/acq-2498/add-constant-backoff branch from a293070 to d974ef1 Compare April 4, 2023 09:21
@sonarqubecloud
Copy link

sonarqubecloud bot commented Apr 4, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

Comment on lines +20 to +26
t.Run("value is capped at max count", func(t *testing.T) {
policy := policies.GetConstantPolicy(time.Millisecond * 100)
assert.Equal(t, policy(10), policy(10))
assert.Equal(t, policy(10), policy(11))
assert.Equal(t, policy(10), policy(12))
assert.Equal(t, policy(10), policy(13))
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this test

@rohits1101 rohits1101 dismissed stale reviews from maetolay and cyberhck via 07c6709 March 21, 2024 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants